<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * ErkanaAuth by Michael Wales
 */

class Auth {

    var $CI;
    
    function Auth()
	{
        $this->CI =& get_instance();
        log_message('debug', 'Authorization class initialized.');
        
        $this->CI->load->database();
    }

    function try_login($condition = array())
	{
        $this->CI->db->select('id');
        $query = $this->CI->db->getwhere('users', $condition, 1, 0);
        if ($query->num_rows != 1)
		{
            return FALSE;
        } 
		else
		{
            $row = $query->row();
            $this->CI->session->set_userdata(array('user_id'=>$row->id));
            return TRUE;
        }
    }
    
    
    function logout()
	{
        $this->CI->session->set_userdata(array('user_id'=>FALSE));
    }
    
    
    function get_user($id)
	{		
        if ($id)
		{
            $query = $this->CI->db->getwhere('users', array('id'=>$id), 1, 0);
            if ($query->num_rows() == 1)
			{
                return $query->row_array();
            }
			else
			{
                return FALSE;
            }
        }
		else
		{
            return FALSE;
        }
    }

}

?>